import os

binary_file='/home/passwd123/XiaoweiGuo/node_modules/.bin/javascript-obfuscator'

# 获取当前脚本或模块的文件路径
script_path = os.path.abspath(__file__)

# 获取文件所在目录的路径
directory_path = os.path.dirname(script_path)


heavy_config=f'{directory_path}/heavy_obfuscator.json'
medium_config=f'{directory_path}/medium_obfuscator.json'
light_config=f'{directory_path}/light_obfuscator.json'

def choose_config(mode):
    if mode=='heavy':
        return f'--config {heavy_config}'
    elif mode=='medium':
        return f'--config {medium_config}'
    elif mode=='light':
        return f'--config {light_config}'
    else:
        return ""




def version():
    return os.system(f'{binary_file} -v')

def obfuscate(in_file,out_file,mode=""):
    os.system(f'{binary_file} {in_file} --output {out_file} {choose_config(mode)}')


if __name__=="__main__":
    version()

    modes=['default','light','medium','heavy']
    good_file='temp/jStap_test/good/good.js'
    good_template='temp/jStap_test/good/good{}.js'
    for mode in modes:
        obfuscate(good_file,good_template.format(mode),mode)


    bad_file = 'temp/jStap_test/bad/bad.js'
    bad_template = 'temp/jStap_test/bad/bad{}.js'
    for mode in modes:
        obfuscate(bad_file, bad_template.format(mode), mode)
